<template>
  <li class="item-panel-item" draggable @dragstart="handleDragItem">
    <div class="item-panel-item-body">
      <div class="item-panel-item-title">
        <span>{{ name }}</span>
      </div>
    </div>
  </li>
</template>

<script>
import EventBus from "../../event-bus/index";
import BusEvents from "../../event-bus/event-types";

export default {
  name: "item-panel-item",
  props: {
    item: {
      type: Object,
      default: () => {
        return {
          name: "矩形",
        };
      },
    },
  },
  computed: {
    name() {
      return this.item.name;
    },
    nodeClass() {
      return this.item.type.split(".")[0];
    },
    nodeType() {
      return this.item.type.split(".")[1];
    },
  },
  methods: {
    handleDragItem(e) {
      EventBus.$emit(BusEvents.INTERACT_ITEM_DRAG, { nodeData: this.item, e });
    },
  },
};
</script>

<style lang="less">
.item-panel-item {
  // width: 160px;
  height: 40px;
  margin: 8px 20px;
  cursor: move;
  user-select: none;

  .item-panel-item-body {
    // width: 100%;
    height: 100%;
    border: 1px solid rgba(0, 0, 0, 0.1);

    display: flex;
    justify-content: center;
    align-items: center;

    &:hover {
      box-shadow: 1px 1px 1px 1px #666;
    }

    .item-panel-item-title {
      height: 24px;
      width: 60%;
      color: black;
      text-align: center;
      z-index: 3;
    }
  }
}
</style>
